<?php
require_once('init.php');

if($sitereg == 1){siteMsg($siteregw);exit;}

$title="用户注册";

$username=isset($_POST['username']) ? trim($_POST['username']): '';
$password=isset($_POST['password']) ? $_POST['password'] : '';
$repassword=isset($_POST['repassword']) ? $_POST['repassword'] : '';
$truename=isset($_POST['truename']) ? trim($_POST['truename']) : '';
$email=isset($_POST['email']) ? trim($_POST['email']) : '';

if(!empty($username)){
$rs = $DB->query("SELECT * FROM ".DB_PREFIX."users WHERE username='$username'");
if ($DB->num_rows($rs) > 0) {
echo "<font color='red' size='5'>该用户名已被注册，请换一个重试!</font><br>\n";
}
else {
$password = md5($password);   // 将明文密码使用md5算法加密
$ctime=time();
$sql = "INSERT INTO ".DB_PREFIX."users (username, password, truename, email,cTime) VALUES";
$sql .= "('$username', '$password', '$truename', '$email','$ctime')";
$rs = $DB->query($sql);
if (!$rs) {
$DB->close();
echo '数据记录插入失败!';
exit;
}
//记录cookie开始
$cookietime = time() + 3600;
setcookie('username',$username,$cookietime);
setcookie('password',$password,$cookietime);
redirect('index.php', 2, '恭喜注册成功，3秒钟后跳转到首页！');
}
$DB->close();
}
$xingTemplate->display('reg');
?>